package com.xiaoyung.easyis.app.demo.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.xiaoyung.easyisapisdk.common.util.PageData;
import com.xiaoyung.easyisapisdk.common.util.bean.BeanUtils;
import com.xiaoyung.easyisapisdk.feign.api.form.DataServiceApi;
import com.xiaoyung.easyisapisdk.feign.api.util.EasyisOpenApi;

public class BaseService {
	public final Logger logger = LoggerFactory.getLogger(this.getClass());

	public EasyisOpenApi api = EasyisOpenApi.getInstance();
	public DataServiceApi dataService = api.dataService;
	
	public <T> T mapToBean(Map<String,Object> map,Class<?> beanClass) {
		@SuppressWarnings("unchecked")
		T p = (T) BeanUtils.mapToBean(map, beanClass);
		return p;
	}
	
	public <T> List<T> mapToBean(List<PageData> list, Class<?> beanClass) {
		List<T> beanList =new ArrayList<>();
		if(list!=null && !list.isEmpty()) {
			for (int i = 0; i < list.size(); i++) {
				PageData pd = list.get(i);
				T bean = mapToBean(pd,beanClass);
				beanList.add(bean);
			}
		}
		return beanList;
	}

	
	public PageData beanToPd(Object bean) {
		if(bean!=null) {
			return new PageData(bean);
		}
		return null;
	}
	public List<PageData> beanToPd(List<Object> list) {
		List<PageData> pdList =new ArrayList<>();
		if(list!=null && !list.isEmpty()) {
			for (int i = 0; i < list.size(); i++) {
				Object bean = list.get(i);
				pdList.add(beanToPd(bean));
			}
		}
		return pdList;
	}
}
